package com.zhangyu.shadow.ec.main.personal.profile;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.view.View;

import com.zhangyu.shadow.core.delegate.ShadowDelegate;
import com.zhangyu.shadow.ec.R;
import com.zhangyu.shadow.ec.R2;
import com.zhangyu.shadow.ec.main.personal.list.ListBean;
import com.zhangyu.shadow.ec.main.personal.list.ListItemType;
import com.zhangyu.shadow.ec.main.personal.list.ListMenuAdapter;

import java.util.ArrayList;

import butterknife.BindView;

/**
 * @author zhangyu
 * @date 2018/1/4
 */

public class UserProfileDelegate extends ShadowDelegate {
    @BindView(R2.id.toolbar)
    Toolbar mToolbar;
    @BindView(R2.id.recycler_view)
    RecyclerView mRecyclerView;
    @Override
    public Object setLayout() {
        return R.layout.delegate_user_profile;
    }

    @Override
    public void onBindView(@Nullable Bundle savedInstanceState, View rootView) {
        initToolbar();
    }

    private void initToolbar() {
        ActionBar actionBar = ((AppCompatActivity) _mActivity).getSupportActionBar();
        if (actionBar != null) {
            actionBar.setDisplayHomeAsUpEnabled(true);
        }
        mToolbar.setTitle("用户信息");
        mToolbar.setNavigationIcon(R.drawable.ic_arrow_back_white_24dp);
        mToolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                pop();
            }
        });
    }

    @Override
    public void onLazyInitView(@Nullable Bundle savedInstanceState) {
        super.onLazyInitView(savedInstanceState);
        ListBean avatar = new ListBean.Builder()
                .setItemType(ListItemType.ITEM_AVATAR)
                .setUrl("http://i9.qhimg.com/t017d891ca365ef60b5.jpg")
                .setId(1)
                .build();
        ListBean name = new ListBean.Builder()
                .setItemType(ListItemType.ITEM_TEXT)
                .setName("姓名")
                .setValue("未设置姓名")
                .setId(2)
                .build();
        ListBean gender = new ListBean.Builder()
                .setItemType(ListItemType.ITEM_TEXT)
                .setName("性别")
                .setValue("未设置性别")
                .setId(3)
                .build();
        ListBean birthDay = new ListBean.Builder()
                .setItemType(ListItemType.ITEM_TEXT)
                .setName("生日")
                .setValue("未设置生日")
                .setId(4)
                .build();
        ArrayList<ListBean> listBeen = new ArrayList<>();
        listBeen.add(avatar);
        listBeen.add(name);
        listBeen.add(gender);
        listBeen.add(birthDay);
        mRecyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
        mRecyclerView.setAdapter(new ListMenuAdapter(listBeen));
        mRecyclerView.addOnItemTouchListener(UserProfileItemClickListener.create(this));
    }
}
